home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / sightmap / auxprocs.bas next >
BASIC Source File  |  1999-02-24  |  8KB  |  307 lines

  1. Attribute VB_Name = "auxProcs"
  2. Option Explicit
  3.  
  4. 'MODULE -- auxProcs -- auxProcs.bas
  5.  
  6. '--------------------------------------------------------------------------
  7. '<Purpose>
  8. '       Provide helper functions and procedures to the application.
  9. '
  10. '--------------------------------------------------------------------------
  11.  
  12. Public gSites As New Collection
  13. Public gLoadingSite As Boolean
  14. Private mRow As Integer
  15.  
  16. '--------------------------------------------------------------------------
  17. '<Purpose>
  18. '   Interrogate the source directory for files matching the file masks.
  19. '   Recursive if indicated by blnRecurse.
  20. '
  21. '<Syntax>
  22. '   FindFiles(TRUE, Path, Filter, SiteID)
  23. '
  24. '<Assumptions>
  25. '   There is at least one filter defined, and the path is a valid path.
  26. '
  27. '<Returns>
  28. '   Nothing.  The file list is placed in a global class variable.
  29. '
  30. '<Author>
  31. '   HBW
  32. '
  33. '--------------------------------------------------------------------------
  34. Public Sub FindFiles(ByVal blnRecurse As Boolean, _
  35.         ByVal strPath As String, ByVal strFilter As String, ByVal intSiteID)
  36.         
  37. On Error GoTo FindFiles_Err
  38.  
  39. Dim intFileCount             As Integer
  40. Dim blnStop                  As Boolean
  41. Dim strFile                  As String
  42. Dim intResult                As Integer
  43. Dim strDirectories()         As String
  44. Dim intDirCount              As Integer
  45. Dim intDirSearch             As Integer
  46.  
  47.     intFileCount = gSites(intSiteID).FileCount
  48.     intDirCount = 0
  49.      
  50.     ReDim strDirectories(0)
  51.  
  52.     strFile = Dir(strPath & "\" & "*" & strFilter)
  53.     Do While strFile <> ""
  54.         intFileCount = intFileCount + 1
  55.         gSites(intSiteID).FileCount = gSites(intSiteID).FileCount + 1
  56.         gSites(intSiteID).FileEntry(intFileCount) = strPath & "\" & UCase$(strFile)
  57.         strFile = Dir
  58.     Loop
  59.     
  60.     If blnRecurse Then
  61.         'Build list of directories
  62.         strFile = Dir(strPath & "\*.*", vbDirectory)
  63.         Do While (strFile <> "")
  64.             If strFile <> "." And strFile <> ".." Then
  65.                 intResult = GetAttr(strPath & "\" & strFile) And vbDirectory
  66.                 If intResult <> 0 Then
  67.                     intDirCount = intDirCount + 1
  68.                     ReDim Preserve strDirectories(intDirCount)
  69.                     strDirectories(intDirCount - 1) = strFile
  70.                 End If
  71.             End If
  72.             strFile = Dir
  73.         Loop
  74.         
  75.         'Recurse through all directories
  76.         For intDirSearch = 0 To intDirCount - 1
  77.             Call FindFiles(True, strPath & "\" & strDirectories(intDirSearch), strFilter, intSiteID)
  78.         Next intDirSearch
  79.         
  80.         'Reset list for recursion unwinding
  81.         Erase strDirectories
  82.         ReDim strDirectories(0)
  83.         intDirCount = 0
  84.         
  85.     End If
  86.         
  87. Exit Sub
  88. FindFiles_Err:
  89.  
  90.     MsgBox CStr(Err.Number) & " -- " & Err.Description, vbCritical, "RegArbiter"
  91.        
  92. End Sub
  93.  
  94. '--------------------------------------------------------------------------
  95. '<Purpose>
  96. '   Create a new instance of Site for use.
  97. '
  98. '<Syntax>
  99. '   AddSite(SiteID)
  100. '
  101. '<Assumptions>
  102. '   None.
  103. '
  104. '<Returns>
  105. '   Nothing.  The new site is added to a global collection variable, gSites
  106. '
  107. '<Author>
  108. '   HBW
  109. '
  110. '--------------------------------------------------------------------------
  111.  
  112. Public Sub AddSite(NewID As String)
  113.  
  114. Dim NewSite As New Site
  115. Dim id As String
  116.     
  117.     'get a random id
  118.     id = CStr(Int((10000 - 1 + 1) * Rnd + 10000))
  119.    
  120.     NewID = id
  121.     
  122.     With NewSite
  123.         .SiteID = id
  124.         .FilterCount = 2
  125.         .FilterEntry(1) = "asp"
  126.         .FilterEntry(2) = "htm"
  127.     End With
  128.     
  129.     gSites.Add NewSite, id
  130.     
  131. End Sub
  132. '--------------------------------------------------------------------------
  133. '<Purpose>
  134. '   Builds an adjacency matrix and other lists to help diagram the site.
  135. '
  136. '<Syntax>
  137. '   MapMe(SiteID)
  138. '
  139. '<Assumptions>
  140. '   A file list has been provided.
  141. '
  142. '<Returns>
  143. '   Nothing.  The matrix is stored in the Class variable.
  144. '
  145. '<Author>
  146. '   HBW
  147. '
  148. '--------------------------------------------------------------------------
  149. Public Sub MapMe(ByVal SiteID As String)
  150.  
  151. Dim sb As StatusBar
  152.  
  153.  
  154.     Set sb = frmMain.sbMain
  155.     sb.SimpleText = "Building Adjacency Matrix"
  156.     gSites(SiteID).BuildMatrix
  157.     sb.SimpleText = ""
  158.  
  159. End Sub
  160.  
  161. '--------------------------------------------------------------------------
  162. '<Purpose>
  163. '   Loads a site's info from a loaded Site class.
  164. '
  165. '<Syntax>
  166. '   LoadSiteForm(frm, S)
  167. '
  168. '<Assumptions>
  169. '   The site has been loaded from disk into S, frm is a loaded
  170. '   instance of frmSiteDefinition.
  171. '
  172. '<Returns>
  173. '   Nothing.
  174. '
  175. '<Author>
  176. '   HBW
  177. '
  178. '--------------------------------------------------------------------------
  179. Sub LoadSiteForm(frm As frmSiteDefinition, S As Site)
  180. Dim i As Integer
  181.  
  182.     frm!lblSiteName = S.SiteName
  183.     frm!lblDirectory = S.MainDirectory
  184.     
  185.     For i = 1 To S.FilterCount
  186.         frm!lblFileMasks = frm!lblFileMasks & "  " & S.FilterEntry(i)
  187.     Next
  188.     
  189.     For i = 1 To S.FileCount
  190.         frm!lstFiles.AddItem S.FileEntry(i)
  191.     Next
  192.     
  193.     frm!txtRoot = S.Root
  194.     
  195.     frm.mSiteID = S.SiteID
  196.     
  197.     If S.ChooseRoot Then
  198.         frm!optDefine = True
  199.     Else
  200.         frm!optDivined = True
  201.     End If
  202.     
  203. End Sub
  204. '--------------------------------------------------------------------------
  205. '<Purpose>
  206. '   Recursively creates a treeview node structure from the adjacency lists.
  207. '
  208. '<Syntax>
  209. '   MakeExcelFile(tv)
  210. '
  211. '<Assumptions>
  212. '   The class has a valid matrix.
  213. '
  214. '<Returns>
  215. '   Handle to the built treeview control.
  216. '
  217. '<Author>
  218. '   HBW
  219. '
  220. '--------------------------------------------------------------------------
  221. Sub MakeExcelFile(tv As TreeView)
  222.  
  223. Dim xl As Excel.Application
  224. Dim n As Node
  225.  
  226.     'Initialize global row counter
  227.     mRow = 1
  228.     
  229.     'Open a new version of Excel
  230.     Set xl = New Excel.Application
  231.     
  232.     'show excel and add a new workbook
  233.     xl.Visible = True
  234.     xl.Workbooks.Add
  235.     
  236.     'set recursion loop invariant to first (root) node
  237.     Set n = tv.Nodes.Item(1)
  238.     
  239.     'set root node value
  240.     xl.Range(("A1")).Value = n.Text
  241.     
  242.     'Kick the recursion off, printing in depth first manner
  243.     Call TraverseChildren(tv, n, xl, 1)
  244.  
  245.     'Release excel object
  246.     Set xl = Nothing
  247.     
  248. End Sub
  249. '--------------------------------------------------------------------------
  250. '<Purpose>
  251. '   Performs the recursion of exploding each child and inserting the
  252. '   children correctly
  253. '
  254. '<Syntax>
  255. '   TraverseChildren(TreeViewCtl, CurrentNode, ExcelInstance, CurrentCol)
  256. '
  257. '<Assumptions>
  258. '   None.
  259. '
  260. '<Returns>
  261. '   None.
  262. '
  263. '<Author>
  264. '   HBW
  265. '
  266. '--------------------------------------------------------------------------
  267. Sub TraverseChildren(tv As TreeView, n As Node, _
  268.     xl As Excel.Application, Depth As Integer)
  269.  
  270. 'Recursive
  271.  
  272. Dim i As Integer        'lcv pointing to current child
  273. Dim CellCol As String   'horizontal positioning for printing to excel
  274.  
  275.     'which column are we currently on for this recursion?
  276.     CellCol = Chr(Depth + 65)
  277.         
  278.     'If we have no children, exit
  279.     If n.Children > 0 Then
  280.         'set i to the index of the first child
  281.         i = n.Child.Index
  282.         'increase the row count
  283.         mRow = mRow + 1
  284.         'output the value to the correct cell
  285.         xl.Range((CellCol & mRow)).Value = n.Child.Text
  286.         
  287.         'Recurse with the first child
  288.         Call TraverseChildren(tv, tv.Nodes(i), xl, Depth + 1)
  289.         
  290.         While i <> n.Child.LastSibling.Index
  291.         'if there are more children, process in order, depth first
  292.             'increase the row count
  293.             mRow = mRow + 1
  294.             'output the value to the correct cell
  295.             xl.Range((CellCol & mRow)).Value = tv.Nodes(i).Next.Text
  296.             'advance the index to the next child
  297.             i = tv.Nodes(i).Next.Index
  298.             'Recurse with subsequent children
  299.             Call TraverseChildren(tv, tv.Nodes(i), xl, Depth + 1)
  300.         Wend
  301.         
  302.     End If
  303.     
  304. End Sub
  305.     
  306.  
  307.